package com.znyj.cloud.chain;


import com.znyj.cloud.chain.server.HttpsServer;
import com.znyj.cloud.chain.server.ServerInit;
import com.znyj.cloud.chain.server.TCPServer;
import com.znyj.cloud.chain.util.SpringContextHelper;


import com.znyj.cloud.device.util.ServerEnvUtil;
import com.znyj.cloud.thrift.ThriftService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Properties;


/**
 * Created by gaoliwei on 15-1-14.
 */
public class Run {
    private static final Logger logger = Logger.getLogger(Run.class);


    public static void main(String[] args) {
        logger.info("*****************************************");
        logger.info("*****************************************");
        logger.info("bulid time:" + "");
        logger.info("*****************************************");
        logger.info("*****************************************");

        //初始化
        initConfig();
        ServerInit serverInit = SpringContextHelper.getBean(ServerInit.class);
        serverInit.init();

        //开始TCP服务
        TCPServer tcpServer = SpringContextHelper.getBean(TCPServer.class);
        new Thread(tcpServer).start();

        //开始THRIFT服务
        ThriftService thriftService = new ThriftService();
        new Thread(thriftService).start();

//        HttpsServer httpsServer = SpringContextHelper.getBean(HttpsServer.class);
//        new Thread(httpsServer).start();
        logger.info("this is server begin!!!!!!!!!!!!!!!!!!!!!!");
    }

    public static void initConfig() {
        logger.info("spring 配置启动开始");
        new ClassPathXmlApplicationContext("/chain/applicationContext-chain.xml");
        logger.info("spring 配置启动结束");
        logger.info("当前的环境变量:" + ServerEnvUtil.getServerEnv());

    }
}